var keystone = require('keystone');

exports = module.exports = function (req, res) {

    const locals = res.locals;
    locals.data = {
        user: locals.user
    };

    if (!locals.data.user && req.path === '/login') {

        return keystone.next_app.render(req, res, '/login', req.query);

    } else if (locals.data.isLogin) {

        return res.redirect('/index');

    } else {
        return res.json(locals.data);
    }


}


